﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JMI_Nucleo.Classe
{
    public static class Formulario
    {
        private static System.Windows.Forms.Form f;
        private static Type t;

        internal static System.Windows.Forms.Form FormTemp
        {
            get
            {
                try
                {
                    if (f == null)
                        f = (System.Windows.Forms.Form)Activator.CreateInstance(t);
                    return f;
                }
                catch (Exception exc)
                {
                    throw new Exception(exc.Message);
                }
            }
        }

        public static void AbrirFormulario(string Namespace_FormName, bool System_Modal)
        {
            t = Type.GetType(Namespace_FormName);

            if (t != null)
            {
                System.Windows.Forms.Form localForm = FormTemp;
                
                if (System_Modal)
                    localForm.ShowDialog();
                else
                    localForm.Show();
            }
        }

        public static void FecharFormulario(string Namespace_FormName)
        {
            t = Type.GetType(Namespace_FormName);

            if (t != null)
            {
                System.Windows.Forms.Form localForm = FormTemp;
                localForm.Close();
                localForm.Dispose();
            }
        }
    }
}
